require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../lib/flexible')
require('../font/iconfont.css')
require('../css/mine.less')
require('../css/commCss/footer.less')
    //引入axios
const axios = require('axios')
const util = require('../util/util')
    //导入weui
require("weui")
const weui = require("weui.js")

document.addEventListener('DOMContentLoaded', function() {

    /* 获取元素 */
    let imgurl = document.querySelector("#imgurl"); //头像地址
    let nickname = document.querySelector("#nickname"); // 昵称
    let sign = document.querySelector("#sign"); // 签名
    let dynamicCount = document.querySelector("#dynamicCount"); // 动态数量
    let times = document.querySelector("#times"); // 时间
    let calorie = document.querySelector("#calorie"); // 卡路里


    util.fixBottomNav('mine')

    let userId = localStorage.getItem('userId')

    // axios.get('http://139.9.177.51:8099/users/mysportsBadge?userId=' + userId)
    // .then(function(res) {
    //     let user = res.data.data.user
    //     console.log(user);
    //     //渲染数据
    //     // if (user.imgurl) {

    //     // }
    // })

    axios.get('http://139.9.177.51:8099/users/mysportsBadge', {
            params: {
                userId
            }
        })
        .then(function(res) {
            let user = res.data.data.user
            let data = res.data.data
            let sports = res.data.data.sports
                // console.log(user);
                // console.log(sports);
                //渲染数据，如果user的xx不为空,那么
            if (user.imgurl) {
                imgurl.src = user.imgurl
            }
            if (user.sign) {
                sign.textContent = user.sign
            }
            nickname.textContent = user.nickname

            dynamicCount.textContent = data.dynamicCount + '条' //运动数量
            times.textContent = sports.times //时间
            calorie.textContent = sports.calorie //卡路里
        })

    document.querySelector('#loginOut').addEventListener('click', function() {
        weui.confirm('您确定要退出吗？', function() {
            console.log('您点了确定按钮');
            //清除本地存储
            localStorage.clear()
                //跳转页面
            location.href = './login.html'
        })
    })
})